package com.browsesoft.resource;

import javax.servlet.http.HttpServletRequest;

import org.w3c.dom.Element;

import com.browsesoft.EntityManager;

/**
 * 授权树model
 */
public class LicenseTreeModel extends RightResourceTreeModel {
	Resource resource;

	Resource byResource;

	public LicenseTreeModel() {
	}

	/**
	 * 初始化model
	 * 
	 * @throws Exception
	 */
	public void init(HttpServletRequest request) throws Exception {
		super.init(request);
		String resourceid = request.getParameter("resourceid");
		if (resourceid != null) {
			resource = (Resource) EntityManager.getInstance().getObject(
					resourceid);
		}

	}

	/**
	 * 设置链接内容
	 * 
	 * @param nodeLink
	 *            链接
	 */
	public void setContextNode(Element nodeLink, Object modelNode)
			throws Exception {
		if (resource != null) {
			String onclick = nodeLink.getAttribute("onclick");
			onclick = onclick.replaceAll("#resourceid#", resource.getID());
			nodeLink.setAttribute("onclick", onclick);
		}
		super.setContextNode(nodeLink, modelNode);
	}
}